<?php

namespace app\common\model;

use think\facade\Cache;
use think\Model;

class NoblePromoModel extends Model
{
    protected static function init()
    {
        NoblePromoModel::afterInsert(function ($user) {
            Cache::rm('noble_promo_list');
        });
        NoblePromoModel::afterUpdate(function ($user) {
            Cache::rm('noble_promo_list');
        });
        NoblePromoModel::afterDelete(function ($user) {
            Cache::rm('noble_promo_list');
        });
    }

    public static function lists(): array
    {
        return Cache::remember('noble_promo_list', function () {
            return static::select()->each(function ($query) {
                $query->reward = $query->reward == 0 ? 0 : bcdiv($query->reward, '100', 2);
            })->toArray();
        });
    }
}